#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;

class Solution{
    public:
    void ans1(vector<vector<int>>& matrix){
        int rows = matrix.size();
        int cols = matrix[0].size();
        int temp[rows+2][cols+2];

        memset(temp, 0, sizeof(temp));
        for(int i = 1; i != rows+1; i++){
            for(int j = 1; j != cols+1; j++){
                temp[i][j] = matrix[i-1][j-1];
            }
        }
        for(int i = 1; i != rows+1; i++){
            for(int j = 1; j != cols+1; j++){
                int sum = 0;
                sum = temp[i-1][j-1] + temp[i-1][j] + temp[i-1][j+1] + temp[i][j-1] + temp[i][j+1] + temp[i+1][j-1] + temp[i+1][j] + temp[i+1][j+1];
                if(sum < 2){
                    matrix[i-1][j-1] = 0;
                }else if(sum == 3){
                    matrix[i-1][j-1] = 1;
                }else if(sum > 3){
                    matrix[i-1][j-1] = 0;
                }else{
                    continue;
                }
            }
        }
        
    }

    void show(vector<vector<int>>& num){
        int rows = num.size();
        int cols = num[0].size();
        for(int i = 0; i != rows; i++){
            for(int j = 0; j != cols-1; j++){
                cout << num[i][j] << " " << ends;
            }
            cout << num[i][cols-1] << endl;
        }
    }
};

void test1(){
    Solution s;
    vector<vector<int>> val = {
        {0,1,0},
        {0,0,1},
        {1,1,1},
        {0,0,0}
    };
    s.ans1(val);
    s.show(val);
}

int main(void){
    test1();

    return 0;
}